﻿@{
    ViewBag.Title = "草稿流程";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script src="~/Content/scripts/plugins/pagination/jquery.pagination-1.2.7.js"></script>
<link href="~/Content/scripts/plugins/pagination/jquery.pagination.css" rel="stylesheet" />
<script>
    var params="";
    $(function () {
        InitialPage();
        GetSchemeType();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $("#taskblock").height($(window).height() - 131);
                $("#itemTree").height($(window).height() - 52);
            }, 200);
            e.stopPropagation();
        });
    }
    //加载树
    function GetSchemeType() {
        $.SetForm({
            url: "../../SystemManage/DataItemDetail/GetDataItemTreeJson",
            param: { EnCode: "FlowSort" },
            success: function (data) {
                $.each(data, function (id, item) {
                    var row = '<li><a data-value="' + item.id + '">' + item.text + '</a></li>';
                    $('#SchemeType').find('ul').append(row);
                });
                $('#SchemeType').find('li>a').click(function () {
                    var id = $(this).attr('data-value');
                    var text = $(this).html();
                    var queryJson = { SchemeType: id };
                    params = { queryJson: JSON.stringify(queryJson) };
                    $("#girdPager").page('remote', 0, params);
                    $('#SchemeType').find('.dropdown-text').html(text);
                });

            }
        })
    }
    //加载表格
    function GetGrid() {
        $("#taskblock").height($(window).height() - 131);
        $("#girdPager").panginationEx({
            url: "../../FlowManage/FlowRoughdraft/GetPageListJson",
            success: function (data) {
                var $flowlist = $("#flowlist");
                $flowlist.html("");
                if (data.length > 0) {
                    $('.no-data').hide();
                }
                else {
                    $('.no-data').show();
                }
                $.each(data, function (i, item) {
                    var _listhtml = '<li><div style="width: 239px; line-height: 38px;margin-top:11px;  float: right;"><a class="btn btn-success createmodel" style="margin-right:4px;">继续编辑</a><a class="btn btn-warning previewmodel" style="margin-right:4px;">模板预览</a><a class="btn btn-danger deletemodel"  >删除草稿</a></div>';
                    _listhtml += '<div style="float: left;">';
                    _listhtml += '<span class="item-text">' + item.f_code + (item.f_customname == "" ? "" : ("/" + item.f_customname)) + '</span>';
                    _listhtml += '<div><span class=\"label label-success-learun\" data-toggle="tooltip" data-placement="top" title="流程分类" >' + item.f_schemetypename + '</span>';
                    _listhtml += '</div><p>By.' + item.f_createusername + '-' + item.f_createdate + (item.f_description == '' ? '' : ' | 备注：' + item.f_description) + '</p>';
                    _listhtml += '</div></li>';
                    var $_listhtml = $(_listhtml);
                    $_listhtml.find('.previewmodel')[0].processSchemeId = item.f_processschemeid;
                    $_listhtml.find('.previewmodel')[0].processname = item.f_code;

                    $_listhtml.find('.createmodel')[0].processInstanceId = item.f_id;
                    $_listhtml.find('.createmodel')[0].processSchemeId = item.f_processschemeid;

                    $_listhtml.find('.deletemodel')[0].processInstanceId = item.f_id;
                    $flowlist.append($_listhtml);
                });
                $('[data-toggle="tooltip"]').tooltip();
                //快速新建
                $('.createmodel').click(function () {
                    var $_btn = $(this).context;
                    var _processSchemeId = $_btn.processSchemeId;
                    var _processInstanceId = $_btn.processInstanceId;
                    dialogOpen({
                        id: "FlowProcessBuider",
                        title: '快速新建',
                        url: '/FlowManage/FlowRoughdraft/FlowProcessBuider?keyValue=' + _processInstanceId + '&processSchemeId=' + _processSchemeId,
                        width: "1100px",
                        height: "700px",
                        btn: null,
                        callBack: function (iframeId) {
                            top.frames[iframeId].AcceptClick();
                        }
                    });
                });
                //模板预览
                $('.previewmodel').click(function () {
                    var $_btn = $(this).context;
                    var _processSchemeId = $_btn.processSchemeId;
                    var _processname = $_btn.processname;
                    top.tablist.newTab({ id: _processSchemeId, title: '流程预览【' + _processname + '】', closed: true, icon: "fa fa fa-eye", url: top.contentPath + '/FlowManage/FlowLaunch/PreviewIndex?processSchemeId=' + _processSchemeId });
                });
                //删除草稿
                $('.deletemodel').click(function () {
                    var $_btn = $(this).context;
                    var $this = $(this);
                    var _ProcessInstanceId = $_btn.processInstanceId;
                    if (_ProcessInstanceId) {
                        $.RemoveForm({
                            url: "../../FlowManage/FlowProcess/DeleteProcess",
                            param: { keyValue: _ProcessInstanceId },
                            success: function (data) {
                                $("#girdPager").page('remote', '', params);
                            }
                        })
                    } else {
                        dialogMsg('请选择需要删除的流程！', 0);
                    }
                });
            },
            sortname: "F_CreateDate desc"
        });

        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = { Keyword: $("#txt_Keyword").val() };
            params = { queryJson: JSON.stringify(queryJson) };
            $("#girdPager").page('remote', 0, params);
        });
    }

    function callback()
    {
        $("#girdPager").page('remote', '', params);
    }
</script>
<div class="titlePanel">
    <div class="title-search">
        <table>
            <tr>
                <td>
                    <div id="SchemeType" class="btn-group">
                        <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择流程分类</a>
                        <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                        <ul class="dropdown-menu"></ul>
                    </div>
                </td>
                <td style="padding-left: 5px;">
                    <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                </td>
                <td style="padding-left: 5px;">
                    <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="toolbar">
        <div class="btn-group">
            <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
        </div>
    </div>
</div>
<div class="taskblockPanel">
    <div id="taskblock" class="taskblock">
        <ul id="flowlist"></ul>
    </div>
    <div id="girdPager" class="m-pagination"></div>
    <div class="no-data"></div>
</div>

